# -*- coding: utf-8 -*-
#--------------------------------------------------------------------------
# Copyright (c) 2009 Barry Schwartz
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

import ocaml

from ocaml import (
    kpse_init_prog,
    kpse_set_program_name,
    kpse_set_program_enabled,
    kpse_find_file,
    kpse_find_glyph,
    kpse_var_value,
    kpse_var_expand,
    kpse_expand,
    kpse_brace_expand,
    kpse_path_expand,
    kpse_path_search,
    )

kpse_gf_format = 0
kpse_pk_format = 1
kpse_any_glyph_format = 2       # ``any'' meaning gf or pk
kpse_tfm_format = 3
kpse_afm_format = 4
kpse_base_format = 5
kpse_bib_format = 6
kpse_bst_format = 7
kpse_cnf_format = 8
kpse_db_format = 9
kpse_fmt_format = 10
kpse_fontmap_format = 11
kpse_mem_format = 12
kpse_mf_format = 13
kpse_mfpool_format = 14
kpse_mft_format = 15
kpse_mp_format = 16
kpse_mppool_format = 17
kpse_mpsupport_format = 18
kpse_ocp_format = 19
kpse_ofm_format = 20
kpse_opl_format = 21
kpse_otp_format = 22
kpse_ovf_format = 23
kpse_ovp_format = 24
kpse_pict_format = 25
kpse_tex_format = 26
kpse_texdoc_format = 27
kpse_texpool_format = 28
kpse_texsource_format = 29
kpse_tex_ps_header_format = 30
kpse_troff_font_format = 31
kpse_type1_format = 32
kpse_vf_format = 33
kpse_dvips_config_format = 34
kpse_ist_format = 35
kpse_truetype_format = 36
kpse_type42_format = 37
kpse_web2c_format = 38
kpse_program_text_format = 39
kpse_program_binary_format = 40
kpse_miscfonts_format = 41
kpse_web_format = 42
kpse_cweb_format = 43
kpse_enc_format = 44
kpse_cmap_format = 45
kpse_sfd_format = 46
kpse_opentype_format = 47
kpse_pdftex_config_format = 48
kpse_lig_format = 49
kpse_texmfscripts_format = 50
kpse_lua_format = 51
kpse_last_format = 52           # one past last index

# Non-standard formats.
kpse_ant_format = 200

def find_resource(resource_name,
                  format = kpse_ant_format,
                  must_exist = True):
    resource = ocaml.find_resource(resource_name, format, must_exist)
    if resource is None:
        raise IOError('Resource not found: \'' + resource_name + '\'')
    return resource
